import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_penting.dart';
import 'package:flutter_learn_vi/src/bean/bean_review.dart';
import 'package:flutter_learn_vi/src/bean/bean_user.dart';
import 'package:flutter_learn_vi/src/common/user_helper.dart';
import 'package:flutter_learn_vi/src/utils/date_utils.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/25.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class PendingReviewListItemWidget extends StatefulWidget {
  final ReviewBean reviewBean;
  final PentingBean pentingBean;
  final int index;

  PendingReviewListItemWidget({
    @required this.reviewBean,
    @required this.index,
    this.pentingBean,
  });

  @override
  _PendingReviewListItemWidgetState createState() =>
      _PendingReviewListItemWidgetState();
}

class _PendingReviewListItemWidgetState
    extends State<PendingReviewListItemWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 16, right: 16, top: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          buildContent(),
          buildHeaderTime(),
          SizedBox(
            height: 10,
          ),
          Divider(),
        ],
      ),
    );
  }

  Widget buildHeaderTime() {
    UserBean userBean = widget.reviewBean.userBean;
    String userName = "***";
    if (userBean != null) {
      userName = ""
          "${userBean.mobile.substring(0, 3)}****${userBean.mobile.substring(7, 11)}";
    }
    String createTime =
        "${TimelineUtil.formatByDateTime(ViDateUtils.getDateTime(widget.reviewBean.createTime), locale: "zh")}";
    return Container(
      margin: EdgeInsets.only(top: 4),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Text(
            "$userName",
            style: TextStyle(fontSize: 12, color: Colors.blueGrey),
          ),
          SizedBox(
            width: 10,
          ),
          Text(
            "$createTime",
            style: TextStyle(fontSize: 12, color: Colors.blueGrey),
          )
        ],
      ),
    );
  }

  Widget buildContent() {
    String content = widget.reviewBean.comment;
    int userId = UserHelper.getInstance.userBean.userId;
    int ruserId = widget.reviewBean.userId;
    int peningUserId = widget.pentingBean.userId;
    bool isSelf = false;
    bool isLouPeople = false;
    print("userId $userId ruserId $ruserId peningUserId $peningUserId");
    if (userId == ruserId) {
      isSelf = true;
    }
    if (peningUserId == ruserId) {
      isLouPeople = true;
    }
    return Container(
      margin: EdgeInsets.only(top: 12, bottom: 20),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: EdgeInsets.only(left: 2, right: 2),
            margin: EdgeInsets.only(left: 0, top: 6),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(2)),
                border: Border.all(color: Colors.blueGrey)),
            child: Text(
              "${widget.index}楼",
              style: TextStyle(fontSize: 8, color: Colors.blueGrey),
            ),
          ),
          isSelf
              ? Container(
            padding: EdgeInsets.only(left: 2, right: 2),
            margin: EdgeInsets.only(left: 10, top: 6),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(2)),
                border: Border.all(color: Colors.deepOrangeAccent)),
            child: Text(
              "我的发布",
              style:
              TextStyle(fontSize: 8, color: Colors.deepOrangeAccent),
            ),
          )
              : Container(),
          isLouPeople
              ? Container(
            padding: EdgeInsets.only(left: 2, right: 2),
            margin: EdgeInsets.only(left: 10, top: 6),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(2)),
                border: Border.all(color: Colors.deepPurpleAccent)),
            child: Text(
              "楼主",
              style:
              TextStyle(fontSize: 8, color: Colors.deepPurpleAccent),
            ),
          )
              : Container(),
          Expanded(
            child: Container(
              margin: EdgeInsets.only(left: 8),
              child: Text(
                "$content",
                style: TextStyle(fontSize: 16, color: Colors.black),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
